<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>

</html>
<script>
    /*--------------------------------------------------------------------------------------------------------*/
    // 深拷贝
    var obj = { name: '李煜', age: 30, sex: true, hobby: ['打球', '听音乐'] };
    function copyObj(obj) {
        var obj2 = Array.isArray(obj) ? [] : {};
        for (var key in obj) {
            if (typeof obj[key] == 'object') {
                obj2[key] = copyObj(osbj[key])
            } else {
                obj2[key] = obj[key];
            }
        }
        return obj2;
    }
    var obj2 = copyObj(obj);
    console.log(obj, obj2);


    /*--------------------------------------------------------------------------------------------------------*/
    //将一个字符串里的大小写反转

    var str = 'Hello World'
    function Reverse(str) {
        str = str.replace(/[a-zA-Z]/g, content => {
            return content.toUpperCase() === content ? content.toLowerCase() : content.toUpperCase()
        })
        return str
    }
    var res = Reverse(str)
    console.log(res);




    /*--------------------------------------------------------------------------------------------------------*/
    // //把url参数解析为一个对象
    const url = 'name=feizhu&from=alibaba&job=frontend&extraInfo=%7B%22a%22%3A%22b%22%2C%22c%22%3A%22d%22%7D';
    function lianjie(url) {
        var obj = {};
        var str = url
        var arr = (str.split('&'));
        arr.forEach((item, index) => {
            let str = item.split('=')[1];
            obj[item.split("=")[0]] = item.split("=")[1];
        })
        return obj;
    }
    console.log(lianjie(url));



    /*----------------------------------------------------------------------------------------------*/

    //字符串排列组合
    str = 'abc'
    // // str2 = 'acb','bac' ,'bca' ,'cba', 'cab'
    function pailie(str) {
        var arr = [];
        if (str.length <= 1) {
            return [str];
        } else {
            for (var i = 0; i < str.length; i++) {
                var char = str[i];
                var newStr = str.slice(0, i) + str.slice(i + 1, str.length);
                // console.log('++++++++++++++++++++++++++++');
                // console.log('char='+c);
                // console.log('str = '+newStr);
                // console.log('i = '+i);
                // console.log('++++++++++++++++++++++++++++');
                var l = pailie(newStr);
                console.log('l = ' + l);
                for (var j = 0; j < l.length; j++) {
                    // console.log('---------------------');
                    var tmp = char + l[j];
                    arr.push(tmp);
                    // console.log('tmp = '+tmp);
                    // console.log('arr = '+arr);
                    // console.log('---------------------');
                }
            }
        }
        return arr;
    };
    console.log('arr result = ' + pailie(str));









</script>